<?php


namespace app\admin\controller\sys;

use app\admin\controller\AController;
use app\model\sys\Area;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
use think\Request;


class AreaController extends AController {


    /**
     * @throws ModelNotFoundException
     * @throws DbException
     * @throws DataNotFoundException
     */
//    public function options(): \think\response\Json
//    {
//        $pid = request()->param('pid');
//        $options = Area::where('pid', $pid)->select();
//        return jsonSuccess([
//            'options' => $options
//        ]);
//    }

    public function options(Request $request): \think\response\Json
    {
        $pid = $request->param('pid');
        $options  = Area::field('id,title,pid')->where('pid', $pid)
            ->select()
            ->toArray();
        // 转为索引数组
        $options = array_values($options);
        return jsonSuccess([
            'options' => $options
        ]);
    }

}
